package com.chis.ms;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test1 {

    public static void main(String[] args) {
        List<String> l = new ArrayList<>();
        File file = new File("C:\\Users\\wlj\\Desktop\\sall.txt");
        if (file.exists()) {
            File[] files = file.listFiles();
            if (null == files || files.length == 0) {
                return;
            } else {
                for (File file2 : files) {
                    FileReader m = null;
                    try {
                        m = new FileReader(file2);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    BufferedReader reader = new BufferedReader(m);
                    while (true) {
                        String nextline = null;
                        try {
                            nextline = reader.readLine();
                            if(nextline != null && nextline.contains("单位编码值不在字典中")){
                                if(!l.contains(nextline)){
                                    l.add(nextline);
                                }
                            }

                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        if (nextline == null) break;
                    }

                }
            }
        } else {
            System.out.println("文件不存在!");
        }
//        List<String> ll = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();
        for(String s : l){
            String tmp = s.substring(s.indexOf("编码名称：")+5);
            String name = tmp.split(",")[0];
            String code = tmp.split("：")[1];
            String sss = name+"#"+code.substring(0,12);
            if(map.containsKey(sss)){
                map.put(sss,map.get(sss)+1);
            }else {
                map.put(sss,1);
            }

//            if(!ll.contains(sss)){
//                ll.add(sss);
//            }

//            System.out.println();
        }
        for(String s1 : map.keySet()){
            System.out.println(s1+"#"+map.get(s1));
        }
    }
}
